package h0910;

import java.util.HashSet;

/**
  * @description 删除子数组的最大得分
  * @author 不知名帅哥
  * @date 2024/9/10 23:27
  * @version 1.0
*/
public class DeleteSubArrayMaxScore {
    public int maximumUniqueSubarray(int[] nums) {

        int start=0;
        int sum=0;
        int maxSum=0;
        HashSet<Integer> set = new HashSet<>();
        for (int end = 0; end < nums.length; end++) {
            while (set.contains(nums[end])){
                set.remove(nums[start]);
                sum-=nums[start];
                start++;
            }
            sum+=nums[end];
            set.add(nums[end]);
            maxSum=Math.max(maxSum,sum);
        }
        return maxSum;
    }
}
